#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e6+100;
typedef long long LL;
const LL mod=998244353;
const LL p=131;
LL f[maxn],h[maxn];
LL a[maxn],tot=0;
LL n;
string s=" ";
LL cal(LL l,LL r){
    return (f[r]%mod-f[l-1]*h[r-l+1]%mod+mod)%mod;
}
bool check(LL len,LL val){
    for(LL i=2;i+len-1<n;i++){
        if(cal(i,i+len-1)==val) return true;
    }
    return false;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  h[0]=1;
  for(LL i=1;i<maxn;i++) h[i]=h[i-1]*p%mod;
  string c;cin>>c;
  s+=c;
  n=s.size()-1;
  for(LL i=1;i<=n;i++){
     f[i]=(f[i-1]*p%mod+s[i])%mod;
  }
  for(LL i=1;i<=n;i++){
    if(cal(1,i)==cal(n-i+1,n)){
        a[++tot]=i;
    }
  }
  LL l=0;LL r=tot;
  while(l<r){
    LL mid=(l+r+1)>>1;
    if(check(a[mid],cal(1,a[mid]))) l=mid;
    else r=mid-1;
  }
  if(l==0){
    cout<<"Just a legend"<<endl;
  }
  else{
    for(LL i=1;i<=a[l];i++){
        cout<<s[i];
    }
    cout<<endl;
  }
return 0;
}
